package com.kongjs.online.preview.config;

import org.springframework.boot.autoconfigure.quartz.SchedulerFactoryBeanCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;

import java.io.IOException;
import java.util.Properties;

@Configuration
public class QuartzConfiguration {
    @Bean
    public SchedulerFactoryBeanCustomizer schedulerFactoryBeanCustomizer() {
        return schedulerFactoryBean ->{
            try {
                ClassPathResource classPathResource = new ClassPathResource("quartz.properties");
                Properties properties = new Properties();
                properties.load(classPathResource.getInputStream());
                schedulerFactoryBean.setQuartzProperties(properties);
                schedulerFactoryBean.start();
            } catch (IOException e) {
                e.printStackTrace();
            }
        };
    }
}
